package ink.lovejinhu.leetcodeMatch;

import java.util.HashMap;

/**
 * @Author: jin
 * @Date: 2021/9/5 11:25
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_5865 {
    public int firstDayBeenInAllRooms(int[] nextVisit) {
        HashMap<Integer, Integer> temp = new HashMap<>();   //key为第i个房间，value是次数
        int allDay = -1;
        int curretDay = 0;  //当前正访问的
        int next = 0;  //将要访问的


        while (temp.size() != nextVisit.length) {
            allDay++;
            if (temp.containsKey(curretDay)) {
                temp.put(curretDay, temp.get(curretDay) + 1);
            } else {
                temp.put(curretDay, 1);
            }
            if (curretDay % 2 == 0) {  //偶数
                next = (curretDay + 1) % nextVisit.length;
            } else {
                next = nextVisit[curretDay];
            }
            curretDay = next;
        }
        return allDay;
    }
}
